package com.test.nnooolwdeaer.activity_fragment_wooden.fragment_wooden;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.bean_wooden.StaticVariate_wooden;
import com.test.nnooolwdeaer.constant_wooden.Constant_wooden;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseFragment_wooden;

public class DataSafetyFragment_wooden extends BaseFragment_wooden {

    private WebView webView_wooden;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_data_safety_wooden, container, false);
        init_wooden(view);
        return view;
    }

    private void init_wooden(View view) {
        try {
            //初始化配置
            initWebViewConfigs_wooden(view);

            switch (StaticVariate_wooden.Select_Country_wooden) {
                case Constant_wooden.Country_Cote_wooden ->//科特
                        webView_wooden.loadUrl(Constant_wooden.Privacy_Cote_wooden);
                case Constant_wooden.Country_Ghana_wooden ->//加纳
                        webView_wooden.loadUrl(Constant_wooden.Privacy_Ghana_wooden);
                case Constant_wooden.Country_Kenya_wooden ->//肯尼亚
                        webView_wooden.loadUrl(Constant_wooden.Privacy_Kenya_wooden);
                case Constant_wooden.Country_Uganda_wooden ->//乌干达
                        webView_wooden.loadUrl(Constant_wooden.Privacy_Uganda_wooden);
                case Constant_wooden.Country_Nigeria_wooden ->//尼日
                        webView_wooden.loadUrl(Constant_wooden.Privacy_Nigeria_wooden);
                case Constant_wooden.Country_Vietnam_wooden ->//越南
                        webView_wooden.loadUrl(Constant_wooden.Privacy_Vietnam_wooden);
            }
        }catch (Exception e){
            if (Constant_wooden.Debug) e.printStackTrace();
        }
    }

    @SuppressLint("SetJavaScriptEnabled")
    private void initWebViewConfigs_wooden(View view) {
        webView_wooden = view.findViewById(R.id.fragment_data_safety_web_view);
        webView_wooden.setInitialScale(100);
        webView_wooden.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                return shouldOverrideUrlLoading(view, request.getUrl().toString());
            }
        });

        WebSettings settings = webView_wooden.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setTextZoom(100);
        settings.setSupportZoom(true);
        settings.setUseWideViewPort(true);
        settings.setUseWideViewPort(true);
        settings.setDomStorageEnabled(true);
        settings.setBuiltInZoomControls(true);
        settings.setLoadWithOverviewMode(true);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);

        settings.setAllowUniversalAccessFromFileURLs(true);
        settings.setAllowFileAccessFromFileURLs(true);
        settings.setAllowContentAccess(true);
    }
}